<!DOCTYPE html>
<html lang="cn" xmlns:th="http://www.thymeleaf.org">
<head th:replace="~{_fragments::common_header(~{::title})}">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../../static/css/bootstrap.min.css"
	th:href="@{/static/css/bootstrap.min.css}" rel="stylesheet">
<script src="../../static/js/jquery-3.2.1.js"
	th:src="@{/static/js/jquery-3.2.1.js}"></script>
<script src="../../static/js/bootstrap.min.js"
	th:src="@{/static/js/bootstrap.min.js}"></script>
<title th:text="${tip.tipTitle} +'- 逍遥论坛'"></title>
</head>
<body>
	<!-- 这是进入贴子查看内容的页面 -->

	<!-- 弹出结果 -->
	<c:if test="${not empty myInfo}">
		<script type="text/javascript" language="javascript">
			{
				alert("<%=request.getAttribute("myInfo")%>");
			}
		</script>
	</c:if>

	<!-- 引入header文件 -->
	<header th:replace=" _fragments:: header"></header>

	<div style="width: 70%; margin: 1% 2% 1% 5%; float: left;">
		<div class="panel panel-default" id="main" style="">
			<div class="panel-heading" style="background-color: white">
				<div>
					<div class="panel-heading" style="background-color: white">
						<a href="<%=basePath%>">逍遥论坛</a> › <a
							th:href="'showTip.do?tipId='+${tip.tipId}"
							th:text="${tip.tipTitle}"></a>
					</div>
	<!-- 				贴子标题
					<h3>
						<span th:text="${tip.tipTitle}"></span> <span style="float: right"
							th:if="${tip.tipIsknot == 0}"> <input type="button"
							class="btn btn-primary" value="结贴"
							th:onclick="'knotTip_confirm('+${tip.tipId}+')'"
							th:if="${session.user!=null&&tip.userId==session.user.userId}" />  <%--发贴人修改贴子有不同的Controller--%>
							<a type="button" class="btn btn-warning"
							th:if="${session.user!=null&&tip.userId==session.user.userId}"
							th:href="'toUserModifyTipPage.do?tipId='+${tip.tipId}">修改</a>

						</span>
					</h3> -->

					<!--  <%--是否结贴：${tip.tip_isKnot}...贴子发表人：${tip.user_id}...当前登录用户：${USER.user_id}...--%> -->
					<!-- <%--贴子发表人 == 当前登录用户：${tip.user_id == USER.user_id}--%> -->
					<span class="label label-info" title="回复数"
						th:text="${tip.tipReplies}+'条回复'"></span> &nbsp; <span
						class="label label-warning" title="点击量"
						th:text="${tip.tipClick}+'次点击'">${tip.tip_click}</span>
					<div>
						<a th:href="'getUserInfo.do?userId='+${tip.userId}"> <span>
								<strong th:text="${tip.userName}"> <!-- <c:choose>
										<c:when test="${empty tip.user.user_nick}">
                                    ${tip.user.user_name}
                                </c:when>
										<c:otherwise>
                                    ${tip.user.user_nick}
                                </c:otherwise>
									</c:choose> -->
							</strong>
						</span>
						</a> <span> <small class="text-muted">发表于：<span
								th:text="${#dates.format(tip.tipPublishtime,'yyyy-MM-dd')}"></span></small>
							<br> <small class="text-muted">更新于：<span
								th:text="${#dates.format(tip.tipModifytime,'yyyy-MM-dd')}"></span></small>
						</span>
					</div>
				</div>
			</div>
			<!-- 这里显示贴子正文 -->
			<ul class="list-group" style="width: 100%">
				<li class="list-group-item" th:text="${tip.tipContent}"></li>
			</ul>
		</div>

		<!-- 这里显示贴子的回复 -->
		<ul class="list-group" style="width: 100%">
			<!-- 遍历并显示回复 -->
			<!-- <c:forEach items="${replies}" var="reply"> -->
			<li class="list-group-item" th:each="reply,iterStat: ${replys}">
				<div style="height: 120px;">
					<div>
						<a th:href="'getUserInfo.do?userId='+${reply.userId}"> <strong>
								<span th:text="${reply.userName}"></span> <!-- 显示发表回复的用户昵称 --> <!-- <c:choose>
										<c:when test="${empty reply.user.user_nick}">
                                        ${reply.user.user_name}
                                    </c:when>
										<c:otherwise>
                                        ${reply.user.user_nick}
                                    </c:otherwise>
									</c:choose> -->
						</strong>
						</a> <small class="text-muted"> <!-- 显示回复发表的时间 --> <span
							th:text="${#dates.format(reply.replyPublishtime,'yyyy-MM-dd')}"></span>
						</small>
					</div>
					<div style="height: 100px; overflow: auto; word-wrap: break-word;"
						th:text="${reply.replyContent}">
						<!-- 这里显示回复的正文 -->
						<!-- <c:out value="${reply.reply_content}"></c:out> -->
					</div>
				</div>
			</li>
			<!-- </c:forEach> -->
		</ul>

		<div class="panel panel-default" style="">
			<div class="panel-heading" style="background-color: white">回复本贴</div>
			<div class="panel-body">
				<div class="form-group" th:switch="${tip.tipIsknot}">
					<!-- 非删除或结贴的贴子才能回复 -->
						<span th:case="1">已结贴！不允许回复。</span>
						<div th:case="*">
							<div  th:if="${session.user!=null}" th:switch="${session.user.userStatus}">
								<!-- 被锁定的用户不能回贴 -->
								<span th:case="2">您的账号已被锁定！不能回贴，请联系管理员解锁。</span>
								<!-- 这里是发表回复的表单 -->
								<form th:case="*" action="publishReply.do" method="post"
									id="myReplyForm">
									<input type="hidden" name="tipId" th:value="${tip.tipId}">
									<!-- 这里显示输入回复内容的文本框 -->
									<textarea class="form-control" rows="3" name="replyContent"
										id="replyContent" required></textarea>
									<br /> <input type="button" class="btn btn-success btn-sm"
										value="发表" onclick="publishReply_confirm()" />
								</form>
							</div>
						<!-- 如果用户没有登录则取消文本框 -->
						<input th:if="${session.user==null}" type="button"
							class="btn btn-warning btn-sm" value="请先登录"
							th:href="'toLoginPage.do?tipId='+${tip.tip_id}" />
				</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 引入侧边栏文件 -->
	<!-- <%@ include file="side.jsp"%> -->
	<nav th:replace="side:: nav"></nav>

	<!-- 引入footer文件 -->
	<!-- <%@ include file="footer.jsp"%> -->
	<footer th:replace="_fragments:: footer"></footer>
	<script>
		function publishReply_confirm() {
			var form = document.getElementById("myReplyForm"); // 由id获取表单
			var replycontent = form.replyContent.value; // 获取输入的回复内容
			if (replycontent == '') {
				alert("请填写回复内容！");
			} else {
				var r = confirm("确定发表该回复?")
				if (r == true) {
					/*
					// 处理textarea的换行符
					var myTextArea = document.getElementById("replyContent");
					var contentValue = myTextArea.value;
					contentValue = contentValue.replace('<br />','/n');
					myTextArea.value = contentValue;
					 */
					form.submit(); // 提交表单
				} else {
				}
			}
		}

		/**
		 * 点击结贴按钮时触发事件
		 * @author rk 2020-02-18 21:55
		 * @param tipId 贴子ID
		 */
		function knotTip_confirm(tipId) {
			var r = confirm("确定结贴？结贴后不能再被回复。")
			if (r == true) {
				// alert(tipId);
				// 用户结贴操作
				window.location.href = '<%=basePath%>userKnotTip.do?tipId=${tip.tip_id}';
			} else {
			}
		}
	</script>

</body>
</html>